/*
 * main.qml 主页（首页）
 */
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
import QtGraphicalEffects 1.15

Item {
    id: root
    width: 1024
    height: 768

    /* property 定义开始 */
    // 信号
    signal nextPage(); // 切换到下一页
    signal prevPage(); // 切换到上一页
    signal opening(); // 打开
    signal program(); // 程序
    signal maintenance(); // 维护
    signal setting(); // 设置
    /* property 定义结束 */

    // 主窗体
    ColumnLayout {
        anchors.fill: parent
        spacing: 0

        // 主界面
        Rectangle {
            id: mainPage
            Layout.fillWidth: true
            Layout.preferredHeight: parent.height - buttonContainer.height - 10
            Layout.alignment: Qt.AlignTop

            // 标题
            TabbarNav {
                id: tabNav
                width: parent.width
                anchors.top: parent.top
                isEnable: true
                title: "96道上位机软件"

                onReturnSig: {
                    console.log("tabbar nav")
                }
                z: 999
            }

            // 背景
            Image {
                anchors.fill: parent
                id: background
                source: "qrc:/images/main_background.jpg"
            }

            // 左右箭头按钮
            Rectangle {
                width: 50
                height: 50
                color: "transparent"
                anchors.verticalCenter: parent.verticalCenter
                anchors.right: parent.right

                RightArrowButton {
                    id: rightarw
                    anchors.fill: parent
                    onClicked: root.nextPage() // 切换到下一页
                }
            }

            Rectangle {
                width: 50
                height: 50
                color: "transparent"
                anchors.verticalCenter: parent.verticalCenter
                anchors.left: parent.left

                LeftArrowButton {
                    id: leftarw
                    anchors.fill: parent
                    onClicked: root.prevPage() // 切换到上一页
                }
            }

            ColumnLayout {
                anchors.fill: parent
                Layout.topMargin: 0
                spacing: 0

                // 新建实验按钮
                NewExpButton {
                    Layout.preferredWidth: 353
                    Layout.preferredHeight: 353
                    Layout.alignment: Qt.AlignCenter
                }

                // 通信状态
                Rectangle {
                    Layout.preferredHeight: 18
                    Layout.leftMargin: 16
                    Layout.alignment: Qt.AlignBottom | Qt.AlignLeft
                    Layout.bottomMargin: 8
                    color: "transparent"

                    RowLayout {
                        anchors.fill: parent
                        spacing: 10

                        Label {
                            font.pixelSize: 16
                            font.family: "Alibaba PuHuiTi"
                            color: "#FFF"
                            text: qsTr("通信状态：")
                        }

                        Image {
                            Layout.preferredWidth: 18
                            Layout.preferredHeight: 18
                            source: "qrc:/icons/net_status_connected.png"
                        }

                        Label {
                            font.pixelSize: 16
                            font.family: "Alibaba PuHuiTi"
                            color: "#FFF"
                            text: qsTr("已连接")
                        }
                    }
                }
            }
        }

        // 操作按钮
        Rectangle {
            id: buttonContainer
            Layout.preferredWidth: openExp.width * 4 + 10 * 4
            Layout.preferredHeight: 70
            color: "transparent"
            Layout.alignment: Qt.AlignCenter
            Layout.topMargin: 5
            Layout.bottomMargin: 5

            RowLayout {
                anchors.fill: parent
                spacing: 10
                Layout.margins: 0

                MainButton {
                    id: openExp
                    showText: "打开"
                    Layout.preferredWidth: 93
                    Layout.preferredHeight: 70
                    labelPath: "qrc:/icons/open.svg"
                    disabledLabelPath: "qrc:/icons/open_disabled.svg"

                    onReleased: root.opening()
                }

                MainButton {
                    id: processing
                    showText: "程序"
                    Layout.preferredWidth: 93
                    Layout.preferredHeight: 70
                    labelPath: "qrc:/icons/program.svg"
                    disabledLabelPath: "qrc:/icons/program_disabled.svg"

                    onReleased: root.program()
                }

                MainButton {
                    id: maintenance
                    showText: "维护"
                    Layout.preferredWidth: 93
                    Layout.preferredHeight: 70
                    labelPath: "qrc:/icons/maintenance.svg"
                    disabledLabelPath: "qrc:/icons/maintenance_disabled.svg"

                    onReleased: root.maintenance()
                }

                MainButton {
                    id: setting
                    showText: "设置"
                    Layout.preferredWidth: 93
                    Layout.preferredHeight: 70
                    labelPath: "qrc:/icons/setting.svg"
                    disabledLabelPath: "qrc:/icons/setting_disabled.svg"

                    onReleased: root.setting()
                }
            }
        }
    }
}
